// 基本类型
let bool: boolean = true;
let num: number = 666;
let str: string = "hello world";
let str2: string = `${str} 这是TS`;

// 数组类型
let arr: number[] = [1, 2, 3];
let arr2: Array<number | string> = [4, 5, 6, "hello"];

// 元组类型
let tuple: [number, string] = [1, "hello ts"];
// tuple.push(2);
console.log(tuple[1]);

// 函数类型
let add = (x: number, y: number): number => x + y;
// 定义函数的类型
let compiler: (x: number, y: number) => number;
compiler = (a, b) => a + b;

// 对象类型
// let obj: object = { x: 1, y: 2 };
// { x: number, y: number }
let obj: { x: number, y: number } = { x: 1, y: 2 };
// obj.x = 3;
// console.log(obj);

// undefind、null
let ud: undefined = undefined;
let nl: null = null;

let n: number = 2;
// n = undefined;

// void
let func=()=>{}

// any
let x;
x=[];
x={};

// never
let error=()=>{
    throw new Error('error')
}

let enless=()=>{
    while(true){}
}

// 枚举
enum STATUS {
    FETCHED,
    SAVED=2,
    LOADING=2+1,
    LOADED="hello to".length,
    EXECUTING=Math.random(),
    EXECUTED=5,
}
console.log(STATUS.LOADING);
// 字符串枚举
enum MESSAGE{
    SUCCESS="成功",
    FILED="失败",
}
console.log(MESSAGE.FILED);
// 异构枚举
enum MEIJU{
    Y,
    FILED="失败",
}
console.log(MEIJU.FILED);
// 枚举成员的特性
/**
 * 1.成员只读,无法修改
 * 2.value
 * 3.枚举or枚举成员都可以作为单独的类型存在
 */
// STATUS.LOADING=4;
enum N{
    x=1,
    y=2
}
enum M{
    A,
    B
}
let z:N=3;
let s:M=3;
console.log(z===s);
// 常量枚举
const enum NUMBER{
    ONE,
    TWO,
    THREE
}
let count = [NUMBER.ONE,NUMBER.TWO,NUMBER.THREE]